What is fdir?
The fdir npm package is a fast and efficient directory crawler that allows you to read and list files in a directory tree. It is designed to be highly performant and can handle large directories with ease.
What are fdir's main functionalities?
Basic Directory Crawling
This feature allows you to crawl a directory and get a list of all files with their full paths. The code sample demonstrates how to use fdir to crawl a directory and log the list of files.
const { fdir } = require('fdir');
const api = new fdir().withFullPaths().crawl('path/to/directory');
api.withPromise().then(files => console.log(files));
Filtering Files
This feature allows you to filter the files based on a condition. The code sample shows how to filter files to include only JavaScript files.
const { fdir } = require('fdir');
const api = new fdir().withFullPaths().filter(path => path.endsWith('.js')).crawl('path/to/directory');
api.withPromise().then(files => console.log(files));
Using Streams
This feature allows you to use streams to handle the files as they are found. The code sample demonstrates how to use a stream to log each file as it is crawled.
const { fdir } = require('fdir');
const api = new fdir().withFullPaths().crawl('path/to/directory');
api.withStream().on('data', file => console.log(file));
Using Async/Await
This feature allows you to use async/await syntax for better readability and control over asynchronous operations. The code sample shows how to use async/await to crawl a directory and log the list of files.
const { fdir } = require('fdir');
(async () => {
const api = new fdir().withFullPaths().crawl('path/to/directory');
const files = await api.withPromise();
console.log(files);
})();
Other packages similar to fdir
fast-glob
fast-glob is a library for searching files by glob patterns. It is highly performant and supports advanced features like negative globs and multiple patterns. Compared to fdir, fast-glob is more focused on pattern matching and offers a rich set of options for globbing.
readdirp
readdirp is a recursive version of fs.readdir with additional features like filtering and streaming. It is similar to fdir in that it allows you to read directories recursively, but it is less focused on performance and more on providing a simple API for directory traversal.
klaw
klaw is a file system walker that uses streams to traverse directories. It is similar to fdir in its use of streams but is generally slower. klaw is more suitable for applications where streaming is a primary requirement.
The Fastest Directory Crawler & Globber for NodeJS
⚡ The Fastest: Nothing similar (in the NodeJS world) beats fdir
in speed. It can easily crawl a directory containing 1 million files in < 1 second.
💡 Stupidly Easy: fdir
uses expressive Builder pattern to build the crawler increasing code readability.
🤖 Zero Dependencies*: fdir
only uses NodeJS fs
& path
modules.
🕺 Astonishingly Small: < 2KB in size gzipped & minified.
🖮 Hackable: Extending fdir
is extremely simple now that the new Builder API is here. Feel free to experiment around.
* picomatch
must be installed manually by the user to support globbing.
🚄 Quickstart
Installation
You can install using npm
:
$ npm i fdir
or Yarn:
$ yarn add fdir
Usage
import { fdir } from "fdir";
const api = new fdir().withFullPaths().crawl("path/to/dir");
const files = api.sync();
api.withPromise().then((files) => {
});
Documentation:
Documentation for all methods is available here.
📊 Benchmarks:
Please check the benchmark against the latest version here.
🙏Used by:
fdir
is downloaded over 200k+ times a week by projects around the world. Here's a list of some notable projects using fdir
in production:
Note: if you think your project should be here, feel free to open an issue. Notable is anything with a considerable amount of GitHub stars.
- rollup/plugins
- SuperchupuDev/tinyglobby
- pulumi/pulumi
- dotenvx/dotenvx
- mdn/yari
- streetwriters/notesnook
- imba/imba
- moroshko/react-scanner
- netlify/build
- yassinedoghri/astro-i18next
- selfrefactor/rambda
- whyboris/Video-Hub-App
🦮 LICENSE
Copyright © 2024 Abdullah Atta under MIT. Read full text here.